
/**		
 * 
 *	uk.co.lmfm.guppy.view.components.core.AbstractView
 *	
 *	@version 1.00 | Jan 12, 2010
 *	@author Justin Windle
 *  
 **/
 
package uk.co.lmfm.guppy.view.components.core 
{
	import flash.utils.setTimeout;
	import flash.events.Event;
	import flash.display.Sprite;

	/**
	 * AbstractView
	 */
	public class AbstractView extends Sprite implements IViewComponent
	{
		//	----------------------------------------------------------------
		//	PRIVATE MEMBERS
		//	----------------------------------------------------------------

		private var _hidden : Boolean = false;

		//	----------------------------------------------------------------
		//	CONSTRUCTOR
		//	----------------------------------------------------------------

		public function AbstractView()
		{
			hide();
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		}

		//	----------------------------------------------------------------
		//	PUBLIC METHODS
		//	----------------------------------------------------------------

		public function show() : void
		{
			visible = true;
			_hidden = false;
			
			setTimeout(resize, 50);
			//resize();
		}

		public function hide() : void
		{
			visible = false;
			_hidden = true;
		}

		//	----------------------------------------------------------------
		//	PROTECTED METHODS
		//	----------------------------------------------------------------

		protected function resize() : void
		{
		}

		//	----------------------------------------------------------------
		//	EVENT HANDLERS
		//	----------------------------------------------------------------

		private function onAddedToStage(event : Event) : void
		{
			removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
			stage.addEventListener(Event.RESIZE, onStageResized);
			resize();
		}

		private function onStageResized(event : Event) : void
		{
			resize();
		}

		//	----------------------------------------------------------------
		//	PUBLIC ACCESSORS
		//	----------------------------------------------------------------

		public function get hidden() : Boolean
		{
			return _hidden;
		}
	}
}
